/*~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
	Copyright (c) 2012 Spira Shop

	spirashop.com

	VERSION 1.0.0

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~*/

// Requires variable items
function generateItems() {

	// Add format method to String
	//first, checks if it isn't implemented yet
	if (!String.prototype.format) {
	  String.prototype.format = function() {
	    var args = arguments;
	    return this.replace(/{(\d+)}/g, function(match, number) { 
	      return typeof args[number] != 'undefined'
		? args[number]
		: match
	      ;
	    });
	  };
	}

	var imageUrlPrefix = "index_files/itemimages/"
	for (var i=0,len=items.length; i<len; i++)
	{
		items[i].imageUrl = imageUrlPrefix + items[i].imageUrl
	}

	var shelfItemTemplate = 
	'<td class="td simpleCart_shelfItem">' + 
		'<a href="#">' +
			'<img class="img3" src="{1}">' +
		'</a>' + 
		'<p class="text3 item_name">' + 
			'<strong>{0}</strong>' +
		'</p>' +
		'<p class="text3 item_price">' +
			'<strong>Php{2}</strong>' + 
		'</p>' +
		'<a href="javascript:;" class="item_add">' + 
			'<img class="but" src="index_files/but1.jpg">' +
		'</a>' +
		'<p>' +
			'<a class="text4" href="#">Details</a>' + 
		'</p>' +
	'</td>';

	var result = "";

	// Generate contents of table body
	for (var i=0,len=items.length; i<len; i++)
	{
	 var item = items[i];
	 
	 // Start table row on items 0, 3, 6, 9 ...
	 if(i % 3 == 0) {
		result += "<tr>"
	 }
	 // Write actual table cell
	 //document.write(shelfItemTemplate.format(item.description, item.imageUrl, item.price)
	result += shelfItemTemplate.format(item.description, item.imageUrl, item.price);

	 // Start table row on items 2, 5, 8, 11 ...
	 if(i % 3 == 2) {
		result += "</tr>"
	 }
	}
	
	return result;
}
